package com.tg.app;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class HomeWatcherReceiver extends BroadcastReceiver {
    private static final String SYSTEM_DIALOG_REASON_KEY = "reason";
    private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";

    public void setHomeKeyHelperListener(HomeKeyHelperListener homeKeyHelperListener) {
        mHomeKeyHelperListener = homeKeyHelperListener;
    }

    private HomeKeyHelperListener mHomeKeyHelperListener;

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(action)) {
            String reason = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY);
            if (SYSTEM_DIALOG_REASON_HOME_KEY.equals(reason)) {
                if (mHomeKeyHelperListener != null){
                    mHomeKeyHelperListener.onNotify();
                }
            }
        }
    }
    public interface HomeKeyHelperListener {
        void onNotify();
    }
}
